package com.xwaiy.xwaiyrpc.exception;

import com.xwaiy.xwaiyrpc.exception.enums.ErrorCode;

/**
 * RPC自定义异常
 * @Author Xwaiy
 * @Date 2025/9/3
 */
public class RpcException extends RuntimeException {

    private final ErrorCode errorCode;

    public RpcException(ErrorCode errorCode) {
        super(errorCode.getMessage());
        this.errorCode = errorCode;
    }

    public RpcException(ErrorCode errorCode, String message) {
        super(message);
        this.errorCode = errorCode;
    }

    public RpcException(ErrorCode errorCode, Throwable cause) {
        super(errorCode.getMessage(), cause);
        this.errorCode = errorCode;
    }

    public RpcException(ErrorCode errorCode, String message, Throwable cause) {
        super(message, cause);
        this.errorCode = errorCode;
    }

    public ErrorCode getErrorCode() {
        return errorCode;
    }

    public int getCode() {
        return errorCode.getCode();
    }
}